package com.hibikiluler.javalearning.controller;


import com.hibikiluler.javalearning.entity.Comments;
import com.hibikiluler.javalearning.entity.Learn;
import com.hibikiluler.javalearning.service.CommentService;
import com.hibikiluler.javalearning.service.LearnService;
import com.hibikiluler.javalearning.util.Queryinfo;
import com.hibikiluler.javalearning.util.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author
 * @create 2021-12-09 20:31
 */
@RestController
@RequestMapping("/learn")
public class LearnController {

    @Autowired
    private LearnService learnService;

    @Autowired
    private CommentService commentService;

    @ApiOperation(value = "分页查询")
    @PostMapping("/findPage")
    public Result findPage(@RequestBody Queryinfo queryInfo) {
        return learnService.findPage(queryInfo);
    }

    @ApiOperation(value = "查询个人发布的资讯")
    @PostMapping("/findby_{username}")
    public Result findByUserName(@PathVariable("username") String username) {
        return learnService.findByUserName(username);
    }

    @ApiOperation(value = "分页查询评论")
    @PostMapping("/findPageComments")
    public Result findPageComments(@RequestBody Queryinfo queryInfo) {
        return commentService.findPage(queryInfo);
    }

    @ApiOperation(value = "删除咨询信息")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id") Long id) {
        return learnService.delete(id);
    }

    @ApiOperation(value = "清空咨询信息")
    @DeleteMapping("/clear")
    public Result clear() {
        return learnService.clear();
    }

    @ApiOperation(value = "添加咨询信息")
    @PostMapping("/insert")
    public Result insert(@RequestBody Learn learn) {
        return learnService.insert(learn);
    }

    @ApiOperation(value = "修改咨询信息")
    @PutMapping("/update")
    public Result update(@RequestBody Learn learn) {
        return learnService.update(learn);
    }

    @ApiOperation(value = "获取详细信息")
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Long id) {
        return learnService.findInfo(id);
    }

    @ApiOperation(value = "添加评论")
    @PostMapping("/insertcomment")
    public Result insertComment(@RequestBody Comments comments) {
        return commentService.insert(comments);
    }

    @ApiOperation(value = "删除评论")
    @DeleteMapping("/deletecomment/{comment_id}")
    public Result deleteComment(@PathVariable("comment_id") Integer id) {
        return commentService.delete(id);
    }

}
